/**
 * elancom Corporation copy right 2012 - 2015  
 *   
 * $Header: https://192.168.1.224/svn/elancom/product/elancom-platform/trunk/src/main/java/com/elancom/framework/commons/json/parser/Feature.java 1034 2012-07-02 03:09:12Z lanzhouxue $
 * $Id: Feature.java 1034 2012-07-02 03:09:12Z lanzhouxue $
 * $Author: lanzhouxue $
 * $Date: 2012-07-02 11:09:12 +0800 (Mon, 02 Jul 2012) $
 * $Revision: 1034 $
 */
package com.elancom.framework.commons.json.parser;

/**
 * @author elancom
 */
public enum Feature {
	/**
	 * 
	 */
	AutoCloseSource,
	/**
	 * 
	 */
	AllowComment,
	/**
	 * 
	 */
	AllowUnQuotedFieldNames,
	/**
	 * 
	 */
	AllowSingleQuotes,
	/**
	 * 
	 */
	InternFieldNames,
	/**
	 * 
	 */
	AllowISO8601DateFormat,

	/**
	 * {"a":1,,,"b":2}
	 */
	AllowArbitraryCommas,

	/**
     * 
     */
	UseBigDecimal,

	/**
	 * @since 1.1.2
	 */
	IgnoreNotMatch,

	/**
	 * @since 1.1.3
	 */
	SortFeidFastMatch,

	/**
	 * @since 1.1.3
	 */
	DisableASM,

	/**
	 * @since 1.1.7
	 */
	DisableCircularReferenceDetect,

	/**
	 * @since 1.1.10
	 */
	InitStringFieldAsEmpty;

	private Feature() {
		mask = (1 << ordinal());
	}

	private final int mask;

	public final int getMask() {
		return mask;
	}

	public static boolean isEnabled(int features, Feature feature) {
		return (features & feature.getMask()) != 0;
	}

	public static int config(int features, Feature feature, boolean state) {
		if (state) {
			features |= feature.getMask();
		} else {
			features &= ~feature.getMask();
		}

		return features;
	}
}
